package com.leapcloud.crm.core.generate;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @author motorfu
 * @email ffu@maxleap.com
 * @since 2018/9/28 14:04
 */
public class GenerateWebCode extends GenerateBase {

  public static void main(String[] args) throws IOException, SQLException {
//    initModule("sale", "sale");
//    initModule("system", "sys");
    initModule("operation", "operation");
  }


  public static void initModule(String module, String tablePrefix) {
    GenerateCode base = new GenerateCode();
    List<Map<String, Object>> list = base.getTables(tablePrefix);
    for (Map<String, Object> stringObjectMap : list) {
      String tableName = stringObjectMap.get("table_name").toString();
      String tableComment = stringObjectMap.get("table_comment").toString();
      List colunmList = base.getTableColumnsForVO(tableName, tableComment);

      base.webAction(module, tablePrefix, tableName, tableComment);
      base.webReducer(module, tablePrefix, tableName, tableComment);
      base.webCompsIndex(module, tablePrefix, tableName, tableComment);
      base.webCompsAdd(module, tablePrefix, tableName, tableComment);
      base.webCompsEdit(module, tablePrefix, tableName, tableComment);
      base.webCompsForm(module, tablePrefix, tableName, tableComment, colunmList);
      base.webCompsPageIndex(module, tablePrefix, tableName, tableComment, colunmList);
    }
  }

  public static void initAction(String module, String tablePrefix) {
    GenerateCode base = new GenerateCode();
    List<Map<String, Object>> list = base.getTables(tablePrefix);
    for (Map<String, Object> stringObjectMap : list) {
      String tableName = stringObjectMap.get("table_name").toString();
      String tableComment = stringObjectMap.get("table_comment").toString();
      base.webAction(module, tablePrefix, tableName, tableComment);
    }
  }


  public static void initReducer(String module, String tablePrefix) {
    GenerateCode base = new GenerateCode();
    List<Map<String, Object>> list = base.getTables(tablePrefix);
    for (Map<String, Object> stringObjectMap : list) {
      String tableName = stringObjectMap.get("table_name").toString();
      String tableComment = stringObjectMap.get("table_comment").toString();
      base.webReducer(module, tablePrefix, tableName, tableComment);
    }
  }

  public static void initCompsIndex(String module, String tablePrefix) {
    GenerateCode base = new GenerateCode();
    List<Map<String, Object>> list = base.getTables(tablePrefix);
    for (Map<String, Object> stringObjectMap : list) {
      String tableName = stringObjectMap.get("table_name").toString();
      String tableComment = stringObjectMap.get("table_comment").toString();
      base.webCompsIndex(module, tablePrefix, tableName, tableComment);
    }
  }

  public static void initCompsAdd(String module, String tablePrefix) {
    GenerateCode base = new GenerateCode();
    List<Map<String, Object>> list = base.getTables(tablePrefix);
    for (Map<String, Object> stringObjectMap : list) {
      String tableName = stringObjectMap.get("table_name").toString();
      String tableComment = stringObjectMap.get("table_comment").toString();
      base.webCompsAdd(module, tablePrefix, tableName, tableComment);
    }
  }

  public static void initCompsEdit(String module, String tablePrefix) {
    GenerateCode base = new GenerateCode();
    List<Map<String, Object>> list = base.getTables(tablePrefix);
    for (Map<String, Object> stringObjectMap : list) {
      String tableName = stringObjectMap.get("table_name").toString();
      String tableComment = stringObjectMap.get("table_comment").toString();
      base.webCompsEdit(module, tablePrefix, tableName, tableComment);
    }
  }

  public static void initCompsForm(String module, String tablePrefix) {
    GenerateCode base = new GenerateCode();
    List<Map<String, Object>> list = base.getTables(tablePrefix);
    for (Map<String, Object> stringObjectMap : list) {
      String tableName = stringObjectMap.get("table_name").toString();
      String tableComment = stringObjectMap.get("table_comment").toString();
      List colunmList = base.getTableColumnsForVO(tableName, tableComment);
      base.webCompsForm(module, tablePrefix, tableName, tableComment, colunmList);
    }
  }

  public static void initCompsPageIndex(String module, String tablePrefix) {
    GenerateCode base = new GenerateCode();
    List<Map<String, Object>> list = base.getTables(tablePrefix);
    for (Map<String, Object> stringObjectMap : list) {
      String tableName = stringObjectMap.get("table_name").toString();
      String tableComment = stringObjectMap.get("table_comment").toString();
      List colunmList = base.getTableColumnsForVO(tableName, tableComment);
      base.webCompsPageIndex(module, tablePrefix, tableName, tableComment, colunmList);
    }
  }


}
